#delimit ;
set more off;

/*NOTE: For a Mac, file path names use a forward slash (/) but for 
PC's they require a backward slash (\). Make these changes below 
if necessary depending on your computer type. 
*/

*Dropbox paths by user;
if c(username)=="shayaksarkar" {;
	local path "/Users/shayaksarkar/Desktop/ReStat_Data_Publication";
};


/*TABLE A3*/;

cd `path';

use "`path'/dta/final_competition.dta", clear;


** PANEL TO TEST EQUALITY OF MEANS FOR BIAS/SUITABILITY/COMPETITION ;
local se cluster(date_auditor);

cap program drop pairtest;
program define pairtest;
syntax varlist, line(real) column(real);
	disp "varlist is `varlist'";
	tokenize `varlist';
	reg `1' `2', `se';
	
	mat t[`line',`column']=_b[_cons];

	mat t[`line',`column'+1]=_b[_cons]+_b[`2'];

	if abs(_b[`2']/_se[`2']) >1.64 {;
		mat t[`line',`column'+2]=8;
		};
	if abs(_b[`2']/_se[`2']) >1.96 {;
		mat t[`line',`column'+2]=88;
		};
	if abs(_b[`2']/_se[`2']) >2.57 {;
		mat t[`line',`column'+2]=888;
		};

end;

	

cap program drop zline;
program define zline;
	syntax varlist, line(real);

	disp "The varname is `varname'";	
	pairtest `varlist' biaswhole, line(`line') column(1);
	pairtest `varlist' needwhole, line(`line') column(4);
	pairtest `varlist' comp     , line(`line') column(7);
	
end;

cap program drop zline2;
program define zline2;
	syntax varlist, line(real);

	disp "The varname is `varname'";	
	pairtest `varlist' ignorant, line(`line') column(10);

end;

cap program drop zline3;
program define zline3;
	syntax varlist, line(real);

	disp "The varname is `varname'";	
	pairtest `varlist' sophisticated, line(`line') column(13);

end;


mat t=J(40,40,.);

** DO ENTIRE PANEL: QUALITY OF ADVICE;

	** AGENT CHARACTERISTICS;
		local i=1;
		zline govt_und, line(`i++');
		zline lic, line(`i++');
		zline agent_gender, line(`i++');

		local i=`i'+1;

		zline agent_dress_1_5, line(`i++');
		zline agent_infra, line(`i++');

		local i=`i'+2;

	** Location of Visit;
		zline agent_home, line(`i++');
		zline agent_office, line(`i++');
		zline auditor_home, line(`i++');
		zline auditor_office, line(`i++');
		zline other_venue, line(`i++');


	** OBSERVATIONS;
		count if biaswhole==0;
		mat t[15,1]=r(N);
		count if biaswhole==1;
		mat t[15,2]=r(N);

		count if needwhole==0;
		mat t[15,4]=r(N);
		count if needwhole==1;
		mat t[15,5]=r(N);

		count if comp==0;
		mat t[15,7]=r(N);
		count if comp==1;
		mat t[15,8]=r(N);


** MIDDLE PANEL: DISCLOSURE;
	use "`path'/dta/final_disclosure.dta", clear;
	gen ignorant=1-disclosureknowledge;
	

	** AGENT CHARACTERISTICS;
		local i=1;
		zline2 govt_und, line(`i++');
		zline2 lic, line(`i++');
		zline2 agent_gender, line(`i++');

		local i=`i'+1;

		zline2 agent_dress_1_5, line(`i++');
		zline2 agent_infra, line(`i++');

		local i=`i'+2;

	** Location of Visit;
		zline2 agent_home, line(`i++');
		zline2 agent_office, line(`i++');
		zline2 auditor_home, line(`i++');
		zline2 auditor_office, line(`i++');
		zline2 other_venue, line(`i++');


	** OBSERVATIONS;
		count if ignorant==0;
		mat t[15,10]=r(N);
		count if ignorant==1;
		mat t[15,11]=r(N);

** RIGHT MOST PANEL, SOPHISTICATION;
	use "`path'/dta/final_sophistication.dta", clear;
	
	** AGENT CHARACTERISTICS;
		local i=1;
		zline3 govt_und, line(`i++');
		zline3 lic, line(`i++');
		zline3 agent_gender, line(`i++');

		local i=`i'+1;

		local i=`i'+2;
		
		local i=`i'+2;

	** Location of Visit;
		zline3 agent_home, line(`i++');
		zline3 agent_office, line(`i++');
		zline3 auditor_home, line(`i++');
		zline3 auditor_office, line(`i++');
		zline3 other_venue, line(`i++');


	** OBSERVATIONS;
		count if sophisticated==0;
		mat t[15,13]=r(N);
		count if sophisticated==1;
		mat t[15,14]=r(N);


svmat t;
foreach X in t3 t6 t9 t12 t15 {;
	ren `X' zzz`X';
		gen `X'="*" if zzz`X'==8;
		replace `X'="**" if zzz`X'==88;
		replace `X'="***" if zzz`X'==888;
	};
	
aorder t*;

outsheet t1-t30 if _n<100 using "`path'/out/tableA3.csv", comma replace;
